From: Aleksey Kladov Date: Wed, 18 Apr 2018 15:00:21 +0000 (+0300) Subject: Don't try to use the same info if target == host X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~59^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=f7fa1f2ac5bd967cf1ea4ea740a65867ccfbec72;p=cargo.git Don't try to use the same info if target == host The info might be different due to RUSTFLAGS, which, in general, are applied only to target. --- diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index faa7a2e67..a3cd0e19f 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -129,17 +129,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let (host_info, target_info) = { let _p = profile::start("Context::probe_target_info"); debug!("probe_target_info"); - let host_target_same = match build_config.requested_target { - Some(ref s) if s != &build_config.host_triple() => false, - _ => true, - }; - let host_info = TargetInfo::new(config, &build_config, Kind::Host)?; - let target_info = if host_target_same { - host_info.clone() - } else { - TargetInfo::new(config, &build_config, Kind::Target)? - }; + let target_info = TargetInfo::new(config, &build_config, Kind::Target)?; (host_info, target_info) }; diff --git a/tests/testsuite/cfg.rs b/tests/testsuite/cfg.rs index 369f48d16..fa86db836 100644 --- a/tests/testsuite/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -445,3 +445,48 @@ fn any_ok() { .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); } + +// https://github.com/rust-lang/cargo/issues/5313 +#[test] +#[cfg(all(target_arch = "x86_64", target_os = "linux"))] +fn cfg_looks_at_rustflags_for_target() { + let p = project("foo") + .file( + "Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + + [target.'cfg(with_b)'.dependencies] + b = { path = 'b' } + "#, + ) + .file( + "src/main.rs", + r#" + #[cfg(with_b)] + extern crate b; + + fn main() { b::foo(); } + "#, + ) + .file( + "b/Cargo.toml", + r#" + [package] + name = "b" + version = "0.0.1" + authors = [] + "#, + ) + .file("b/src/lib.rs", "pub fn foo() {}") + .build(); + + assert_that( + p.cargo("build --target x86_64-unknown-linux-gnu") + .env("RUSTFLAGS", "--cfg with_b"), + execs().with_status(0), + ); +}